/**
 * 地图拖拽
 * @param {*} app 
 * @param {*} robot 
 */

let dragFlag = false, startPoint;

export const mapDrag = (gl, app, robot) => {
  gl.renderer.plugins.interaction.on("mousedown", (event) => {
    dragFlag = true
    startPoint = { x: event.data.global.x, y: event.data.global.y }
  })

  gl.renderer.plugins.interaction.on("mousemove", (event) => {
    if (dragFlag) {
      const dx = event.data.global.x - startPoint.x;
      const dy = event.data.global.y - startPoint.y;
      app.position.x += dx;
      app.position.y += dy;
      startPoint = { x: event.data.global.x, y: event.data.global.y }
    }
  })

  gl.renderer.plugins.interaction.on("mouseup", (event) => {
    dragFlag = false
  })
}
